package org.wsdltools.profiles.az

;

import java.io.InputStreamReader;
import java.nio.charset.Charset;

import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import org.w3c.dom.Document;

import org.wsdltools.common.model.MEPEnum;
import org.wsdltools.common.model.Repository;
import org.wsdltools.common.model.ProfileEnum;
import org.wsdltools.common.model.ServiceInteraction;
import org.wsdltools.profiles.az.SchemaGenerator;

import groovy.util.GroovyTestCase;

class SchemaGeneratorTest extends GroovyTestCase {
	void testGenerateResponderSchema() {
		XMLUnit.setIgnoreWhitespace(true)
		String xsdPath = "/org/wsdltools/profiles/az/ReportReceptacleResponder.xsd"
		InputStream responderSchema = getClass().getResourceAsStream(xsdPath)
        Document myExpectedSchema = XMLUnit.buildDocument(XMLUnit.getControlParser(), new InputStreamReader(responderSchema, Charset.forName("UTF-8")))
		
		Repository rep = new Repository();
		rep.addServiceInteraction("astrazeneca", "rd:leads", "cm", 1, 0, "ReportReceptacle", "Service contract for reporting a receptacle consumption",null, false, MEPEnum.In, ProfileEnum.AZWS10);
		ServiceInteraction si = rep.getServiceInteraction("ReportReceptacle","astrazeneca", "rd:leads", "cm", 1, 0)
		
		String generatedXSDString = new SchemaGenerator().generateResponderSchema(si)
		Document generatedXSD = XMLUnit.buildDocument(XMLUnit.getControlParser(), new StringReader(generatedXSDString))
		
        Diff myDiff = new Diff(myExpectedSchema, generatedXSD);
        assertTrue("Responder Schema not generated as expected:" + myDiff, myDiff.similar());
	}

	
	void testGenerateDomainSchema() {
		XMLUnit.setIgnoreWhitespace(true)
		String xsdPath = "/org/wsdltools/profiles/az/CmBase.xsd"
		InputStream coreSchema = getClass().getResourceAsStream(xsdPath)
        Document myExpectedSchema = XMLUnit.buildDocument(XMLUnit.getControlParser(), new InputStreamReader(coreSchema, Charset.forName("UTF-8")))
		
		Repository rep = new Repository();
		rep.addServiceInteraction("astrazeneca", "rd:leads", "cm", 1, 0, "ReportReceptacle", "Service contract for reporting a receptacle consumption",null, false, MEPEnum.In, ProfileEnum.AZWS10);
		ServiceInteraction si = rep.getServiceInteraction("ReportReceptacle","astrazeneca", "rd:leads", "cm", 1, 0)
		
		String generatedXSDString = new SchemaGenerator().generateCoreSchema(si)
		Document generatedXSD = XMLUnit.buildDocument(XMLUnit.getControlParser(), new StringReader(generatedXSDString))
		
        Diff myDiff = new Diff(myExpectedSchema, generatedXSD);
        assertTrue("Core Schema not generated as expected:" + myDiff, myDiff.similar());
	}	
	
	
	/**
	void testGenerateInitiatorSchema() {
		XMLUnit.setIgnoreWhitespace(true)
		String xsdPath = "/org/wsdltools/profiles/rivta/RegisterMedicalCertificateInitiator_1.0.xsd"
		InputStream initiatorSchema = getClass().getResourceAsStream(xsdPath)
		Document myExpectedSchema = XMLUnit.buildDocument(XMLUnit.getControlParser(), new InputStreamReader(initiatorSchema, Charset.forName("UTF-8")))
		
		Repository rep = new Repository();
		rep.addServiceInteraction("riv", "insuranceprocess", "healthreporting", 1, 0, "RegisterMedicalCertificate", "Interaction to transfer a new report for sickness","LogicalAddress is the organization id for F�rs�kringskassan.", false, MEPEnum.InOut, ProfileEnum.RIVTABP20);
		ServiceInteraction si = rep.getServiceInteraction("RegisterMedicalCertificate","riv", "insuranceprocess", "healthreporting", 1, 0)
		
		String generatedXSDString = new SchemaGenerator().generateInitiatorSchema(si)
		Document generatedXSD = XMLUnit.buildDocument(XMLUnit.getControlParser(), new StringReader(generatedXSDString))
		
		Diff myDiff = new Diff(myExpectedSchema, generatedXSD);
		assertTrue("Initiator Schema not generated as expected:" + myDiff, myDiff.similar());
	}
	**/
}
